//#include "stdafx.h"

#include "utility/clock.h"



#ifdef __LINUX
	#include "win.h"
#else
	#include <Windows.h>
#endif

//#include "utility_cross_platform.h"
#include <time.h>

#pragma comment(lib,"winmm.lib")

//#include "utility_new.h"

namespace KCore
{

unsigned long g_timeZero = 0;
float g_timeSpeed = 1.f;
unsigned long g_timeSpeedInit = 0;

void set_clockspeed(float speed)
{
	g_timeSpeed = speed;
	if (g_timeSpeed != 1.f)
	{
		g_timeZero = 0;
		g_timeSpeedInit = timeGetTime();
	}
}

void init_clockcount(int num)
{
	g_timeZero = 0-timeGetTime()+num;
	g_timeSpeed = 1.f;
}

unsigned long time_get_clockcount()
{
	if (g_timeSpeed == 1.f)
		return timeGetTime() + g_timeZero;
	return g_timeSpeedInit + (unsigned long)((timeGetTime()- g_timeSpeedInit) * g_timeSpeed);
}


unsigned long clock_ms::gettimenow()
{
	return time_get_clockcount();
}

void sleep_ms(size_t time)
{
	#ifdef __LINUX
	usleep(time*1000);
	#else
	Sleep(time);
	//boost::thread::sleep(time);
	#endif
}

unsigned long clock_s::gettimenow()
{
	return time(0);
}

void sleep_s(size_t time)
{
	#ifdef __LINUX
	sleep(time);
	#else
	Sleep(time*1000);
	#endif

}

};
